package dao

import (
	"fmt"
	"hft/Http/Models/request"

	"gorm.io/gorm"
)

type GetTag struct{}

func (g *GetTag) GetTagList(ids []int, paginate *request.CommonTagSearch, db *gorm.DB) func(db *gorm.DB) *gorm.DB {

	return func(db *gorm.DB) *gorm.DB {
		return db.Where("name LIKE ?", fmt.Sprintf("%%%v%%", paginate.Name)).Scopes(g.justId(ids, db)).Omit("account_id,account_link").Scopes(Paginate(Page(paginate.Page), db)).Order("sort desc")
	}

}

// 判断id
func (g *GetTag) justId(ids []int, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if len(ids) == 0 {
			return db
		} else {
			return db.Where("account_id IN ?", ids)
		}
	}
}

var GetTagDao = new(GetTag)
